/*
 * hello_server.c
 *
 *  Created on: Jun 1, 2014
 *      Author: Lhmily
 */
#include "../include/base.h"

int main(int argc, char **argv) {
	struct sockaddr_in peer;
	char *hname, *sname;
	int peerlen;
	SOCKET s1, s;

	INIT();

	if (argc == 2) {
		hname = NULL;
		sname = argv[1];
	} else {
		hname = argv[1];
		sname = argv[2];
	}

	s = tcp_server(hname, sname);
	do {
		peerlen = sizeof(peer);
		s1 = accept(s, (struct sockaddr *) &peer, &peerlen);
		if (!isvalidsock(s1))
			error(1, errno, "accept failed");
		send(s1, "Hello, world\n", 13, 0);
		CLOSE(s1);
	} while (1);
	EXIT(0);
}
